package org.bzjj.sql;

import java.util.HashMap;

public class SqlSelect {

	private static String startSelect = "SELECT ";
	private static String fromSelect = " FROM ";
	private static String whereSelect = " WHERE ";

	/**
	 * 获取select语句
	 * 
	 * @param table
	 *            表名
	 * @param column
	 *            列名，单列
	 * @param where
	 *            where条件,可为null
	 * @return select语句
	 */
	public static String getSelect(String table, String column,
			HashMap<String, String> where) {
		String str = startSelect + Sql.getKey(column) + fromSelect
				+ Sql.getKey(table);
		if (where == null) {
			return str;
		} else {
			str += whereSelect + Sql.getWhere(where);
			return str;
		}
	}

	/**
	 * 获取select语句
	 * 
	 * @param table
	 *            表名
	 * @param columns
	 *            列名，多列
	 * @param where
	 *            where条件,可为null
	 * @return select语句
	 */
	public static String getSelect(String table, String[] columns,
			HashMap<String, String> where) {

		String str = startSelect + Sql.getKeys(columns) + fromSelect
				+ Sql.getKey(table);
		if (where == null) {
			return str;
		} else {
			str += whereSelect + Sql.getWhere(where);
			return str;
		}

	}
}
